import 'package:flutter/material.dart';
import 'package:xinxuan/common/button_util.dart';
import 'package:xinxuan/common/dialogs/del_dialog.dart';
import 'package:xinxuan/common/dialogs/input_dialog_util.dart';
import 'package:xinxuan/common/dialogs/message_dialog.dart';
import 'package:xinxuan/common/network_image_util.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/controllers/cooperation_controller/cooperation_page_controller.dart';
import 'package:xinxuan/controllers/my_controller/my_page_controller.dart';
import 'package:xinxuan/router/app_routers.dart';
import 'package:x_common_utils/utils/inkWell_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:xinxuan/utils/refresh_util.dart';

class MyPage extends StatelessWidget {

  final CommonPageController commonPageController = Get.find();
  final MyPageController controller = Get.put(MyPageController());

  @override
  Widget build(BuildContext context) {
    // return Scaffold(
    //   backgroundColor: pageBgColor,
    //   body: GetBuilder<MyPageController>(
    //     init: MyPageController(),
    //     builder: (controller) {
    //       return Stack(
    //         children: [
    //           Obx(() => AnimatedContainer(
    //             duration: Duration(milliseconds: 1),
    //             height: controller.bgHeight.value + ScreenUtil().statusBarHeight,
    //             decoration: BoxDecoration(
    //               gradient: LinearGradient(
    //                 begin: Alignment.bottomCenter,
    //                 end: Alignment.topCenter,
    //                 colors: [
    //                   bgPinkColor,
    //                   bgMainColor
    //                 ],
    //               )
    //             ),
    //           )),
    //           Positioned(
    //             child: Column(
    //               children: [
    //                 Obx(() => Container(
    //                   height: 40.h + ScreenUtil().statusBarHeight,
    //                   padding: EdgeInsets.only(top: ScreenUtil().statusBarHeight),
    //                   decoration: BoxDecoration(
    //                     gradient: LinearGradient(
    //                       begin: Alignment.centerLeft,
    //                       end: Alignment.centerRight,
    //                       colors: [
    //                         Color.fromRGBO(254, 7, 15, controller.titleBarOpacity.value),
    //                         Color.fromRGBO(255, 38, 99, controller.titleBarOpacity.value)
    //                       ],
    //                     )
    //                   ),
    //                   child: Row(
    //                     mainAxisAlignment: MainAxisAlignment.end,
    //                     children: [
    //                       Container(
    //                         margin: EdgeInsets.only(right: 16.w),
    //                         child: InkWellUtil.shakeProofInkWell(
    //                           Image.asset(
    //                             'assets/icons/icon_setting.png',
    //                             width: 20.w,
    //                             height: 20.w,
    //                           ), () {
    //                             Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}');
    //                           },
    //                           hoverColor: Colors.transparent,
    //                           splashColor: Colors.transparent,
    //                           highlightColor: Colors.transparent
    //                         ),
    //                       ),
    //                       Container(
    //                         margin: EdgeInsets.only(right: 16.w),
    //                         child: InkWellUtil.shakeProofInkWell(
    //                           Image.asset(
    //                             'assets/icons/icon_msg.png',
    //                             width: 20.w,
    //                             height: 20.w,
    //                           ), () {
    //                             if (commonPageController.isRevirew.value) {
    //                               commonPageController.tabIndex.value = 1;
    //                             } else {
    //                               commonPageController.tabIndex.value = 2;
    //                             }
    //                           },
    //                           hoverColor: Colors.transparent,
    //                           splashColor: Colors.transparent,
    //                           highlightColor: Colors.transparent
    //                         ),
    //                       ),
    //                     ],
    //                   ),
    //                 )),
    //                 Obx(() => Expanded(child: RefreshUtil.easyRefresh(
    //                   scrollController: controller.scrollController,
    //                   onRefresh: () async {
    //                     commonPageController.checkLogin(loading: false);
    //                   },
    //                   slivers: [
    //                     SliverToBoxAdapter(child: _userHead()),
    //                     SliverToBoxAdapter(child: _assets()),
    //                     SliverToBoxAdapter(child: _orderBody(title: '抢购订单', children: [
    //                       Row(
    //                         mainAxisAlignment: MainAxisAlignment.spaceBetween,
    //                         children: [
    //                           _funItem(path: 'assets/icons/icon_to_be_received.png', title: '待收款', num: commonPageController.userData.value.statistics!.seckill![0], width: 65.w, onTap: () {
    //                             Get.toNamed(
    //                               '${AppRouters.COMMON_PAGE}${AppRouters.SECKILL_ORDER_PAGE}',
    //                               arguments: {
    //                                 'tabIndex': 2
    //                               }
    //                             )!.then((value) {
    //                               commonPageController.getUserInfo(loading: false);
    //                             });
    //                           }),
    //                           _funItem(path: 'assets/icons/icon_received.png', title: '待付款', num: commonPageController.userData.value.statistics!.seckill![1], width: 65.w, onTap: () {
    //                             Get.toNamed(
    //                               '${AppRouters.COMMON_PAGE}${AppRouters.SECKILL_ORDER_PAGE}',
    //                               arguments: {
    //                                 'tabIndex': 1
    //                               }
    //                             )!.then((value) {
    //                               commonPageController.getUserInfo(loading: false);
    //                             });
    //                           }),
    //                           _funItem(path: 'assets/icons/icon_sold.png', title: '已售出', num: commonPageController.userData.value.statistics!.seckill![2], width: 65.w, onTap: () {
    //                             Get.toNamed(
    //                               '${AppRouters.COMMON_PAGE}${AppRouters.SECKILL_ORDER_PAGE}',
    //                               arguments: {
    //                                 'tabIndex': 3
    //                               }
    //                             )!.then((value) {
    //                               commonPageController.getUserInfo(loading: false);
    //                             });
    //                           }),
    //                           _funItem(path: 'assets/icons/icon_good.png', title: '我的商品', num: commonPageController.userData.value.statistics!.seckill![3], width: 65.w, onTap: () {
    //                             Get.toNamed(
    //                               '${AppRouters.COMMON_PAGE}${AppRouters.MY_COMMODITY_PAGE}'
    //                             )!.then((value) {
    //                               commonPageController.getUserInfo(loading: false);
    //                             });
    //                           }),
    //                           _funItem(path: 'assets/icons/icon_recovery.png', title: '回收', num: commonPageController.userData.value.statistics!.seckill![4], width: 65.w, onTap: () {
    //                             Get.toNamed(
    //                               '${AppRouters.COMMON_PAGE}${AppRouters.RECOVERY_PAGE}'
    //                             )!.then((value) {
    //                               commonPageController.getUserInfo(loading: false);
    //                             });
    //                           })
    //                         ],
    //                       )
    //                     ], onTap: () {
    //                       Get.toNamed(
    //                         '${AppRouters.COMMON_PAGE}${AppRouters.SECKILL_ORDER_PAGE}',
    //                         arguments: {
    //                           'tabIndex': 0
    //                         }
    //                       );
    //                     })),
    //                     SliverToBoxAdapter(child: _orderBody(title: '商城订单', children: [
    //                       Row(
    //                         mainAxisAlignment: MainAxisAlignment.spaceBetween,
    //                         children: [
    //                           _funItem(path: 'assets/icons/icon_payment.png', title: '待付款', num: commonPageController.userData.value.statistics!.shopping![0], width: 65.w, onTap: () {
    //                             Get.toNamed(
    //                               '${AppRouters.COMMON_PAGE}${AppRouters.STORE_ORDER_PAGE}',
    //                               arguments: {
    //                                 'tabIndex': 1
    //                               }
    //                             );
    //                           }),
    //                           _funItem(path: 'assets/icons/icon_store_received.png', title: '待收货', num: commonPageController.userData.value.statistics!.shopping![1], width: 65.w, onTap: () {
    //                             Get.toNamed(
    //                               '${AppRouters.COMMON_PAGE}${AppRouters.STORE_ORDER_PAGE}',
    //                               arguments: {
    //                                 'tabIndex': 2
    //                               }
    //                             );
    //                           }),
    //                           _funItem(path: 'assets/icons/icon_exchange.png', title: '退换/售后', num: commonPageController.userData.value.statistics!.shopping![2], width: 65.w, onTap: () {
    //                             Get.toNamed(
    //                               '${AppRouters.COMMON_PAGE}${AppRouters.STORE_ORDER_PAGE}',
    //                               arguments: {
    //                                 'tabIndex': 0
    //                               }
    //                             );
    //                           }),
    //                           _funItem(path: 'assets/icons/icon_gift_l.png', title: '赠品', num: commonPageController.userData.value.statistics!.shopping![2], width: 65.w, onTap: () {
    //                             Get.toNamed(
    //                               '${AppRouters.COMMON_PAGE}${AppRouters.GIFT_ORDER_PAGE}'
    //                             );
    //                           })
    //                         ],
    //                       )
    //                     ], onTap: () {
    //                       Get.toNamed(
    //                         '${AppRouters.COMMON_PAGE}${AppRouters.STORE_ORDER_PAGE}',
    //                         arguments: {
    //                           'tabIndex': 0
    //                         }
    //                       );
    //                     })),
    //                     SliverToBoxAdapter(child: Container(
    //                       margin: EdgeInsets.only(top: 12.h),
    //                       padding: EdgeInsets.symmetric(horizontal: 16.w),
    //                       child: ClipRRect(
    //                         borderRadius: BorderRadius.circular(5.w),
    //                         child: Image.asset(
    //                           'assets/images/preferential_bg.jpg',
    //                           width: 343.w,
    //                           height: 130.h,
    //                           fit: BoxFit.cover,
    //                         ),
    //                       ),
    //                     )),
    //                     SliverToBoxAdapter(child: _orderBody(title: '其他信息', showAllBtn: false, topPadding: false, children: _getOtherItem().map((item) {
    //                       return Container(
    //                         padding: EdgeInsets.only(top: 12.h),
    //                         child: Row(
    //                           mainAxisAlignment: MainAxisAlignment.spaceBetween,
    //                           children: item,
    //                         ),
    //                       );
    //                     }).toList())),
    //                     SliverToBoxAdapter(child: SizedBox(height: 38.h))
    //                   ]
    //                 )))
    //               ],
    //             )
    //           )
    //         ],
    //       );
    //     },
    //   ),
    // );
    return Scaffold(
      backgroundColor: pageBgColor,
      body: Stack(
        children: [
          Obx(() => AnimatedContainer(
            duration: Duration(milliseconds: 1),
            height: controller.bgHeight.value + ScreenUtil().statusBarHeight,
            decoration: BoxDecoration(
              gradient: LinearGradient(
                begin: Alignment.bottomCenter,
                end: Alignment.topCenter,
                colors: [
                  bgPinkColor,
                  bgMainColor
                ],
              )
            ),
          )),
          Positioned(
            child: Column(
              children: [
                Obx(() => Container(
                  height: 40.h + ScreenUtil().statusBarHeight,
                  padding: EdgeInsets.only(top: ScreenUtil().statusBarHeight),
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                      begin: Alignment.centerLeft,
                      end: Alignment.centerRight,
                      colors: [
                        Color.fromRGBO(254, 7, 15, controller.titleBarOpacity.value),
                        Color.fromRGBO(255, 38, 99, controller.titleBarOpacity.value)
                      ],
                    )
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: [
                      Container(
                        margin: EdgeInsets.only(right: 16.w),
                        child: InkWellUtil.shakeProofInkWell(
                          Image.asset(
                            'assets/icons/icon_setting.png',
                            width: 20.w,
                            height: 20.w,
                          ), () {
                            Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}');
                          },
                          hoverColor: Colors.transparent,
                          splashColor: Colors.transparent,
                          highlightColor: Colors.transparent
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(right: 16.w),
                        child: InkWellUtil.shakeProofInkWell(
                          Image.asset(
                            'assets/icons/icon_msg.png',
                            width: 20.w,
                            height: 20.w,
                          ), () {
                            if (commonPageController.isRevirew.value) {
                              commonPageController.tabIndex.value = 1;
                            } else {
                              commonPageController.tabIndex.value = 2;
                            }
                          },
                          hoverColor: Colors.transparent,
                          splashColor: Colors.transparent,
                          highlightColor: Colors.transparent
                        ),
                      ),
                    ],
                  ),
                )),
                Obx(() => Expanded(child: RefreshUtil.easyRefresh(
                  scrollController: controller.scrollController,
                  onRefresh: () async {
                    commonPageController.checkLogin(loading: false);
                  },
                  slivers: [
                    SliverToBoxAdapter(child: _userHead()),
                    SliverToBoxAdapter(child: _assets()),
                    SliverToBoxAdapter(child: _orderBody(horizontalPadding: 12.w, title: '抢购订单', children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          _funItem(path: 'assets/icons/icon_to_be_received.png', title: '待收款', num: commonPageController.userData.value.statistics!.seckill![0], width: 65.w, onTap: () {
                            Get.toNamed(
                              '${AppRouters.COMMON_PAGE}${AppRouters.SECKILL_ORDER_PAGE}',
                              arguments: {
                                'tabIndex': 2
                              }
                            )!.then((value) {
                              commonPageController.getUserInfo(loading: false);
                            });
                          }),
                          _funItem(path: 'assets/icons/icon_received.png', title: '待付款', num: commonPageController.userData.value.statistics!.seckill![1], width: 65.w, onTap: () {
                            Get.toNamed(
                              '${AppRouters.COMMON_PAGE}${AppRouters.SECKILL_ORDER_PAGE}',
                              arguments: {
                                'tabIndex': 1
                              }
                            )!.then((value) {
                              commonPageController.getUserInfo(loading: false);
                            });
                          }),
                          _funItem(path: 'assets/icons/icon_sold.png', title: '已售出', num: commonPageController.userData.value.statistics!.seckill![2], width: 65.w, onTap: () {
                            Get.toNamed(
                              '${AppRouters.COMMON_PAGE}${AppRouters.SECKILL_ORDER_PAGE}',
                              arguments: {
                                'tabIndex': 3
                              }
                            )!.then((value) {
                              commonPageController.getUserInfo(loading: false);
                            });
                          }),
                          _funItem(path: 'assets/icons/icon_good.png', title: '我的商品', num: commonPageController.userData.value.statistics!.seckill![3], width: 65.w, onTap: () {
                            Get.toNamed(
                              '${AppRouters.COMMON_PAGE}${AppRouters.MY_COMMODITY_PAGE}'
                            )!.then((value) {
                              commonPageController.getUserInfo(loading: false);
                            });
                          }),
                          // _funItem(path: 'assets/icons/icon_recovery.png', title: '回收', num: commonPageController.userData.value.statistics!.seckill![4], width: 65.w, onTap: () {
                          //   Get.toNamed(
                          //     '${AppRouters.COMMON_PAGE}${AppRouters.RECOVERY_PAGE}'
                          //   )!.then((value) {
                          //     commonPageController.getUserInfo(loading: false);
                          //   });
                          // })
                        ],
                      )
                    ], onTap: () {
                      Get.toNamed(
                        '${AppRouters.COMMON_PAGE}${AppRouters.SECKILL_ORDER_PAGE}',
                        arguments: {
                          'tabIndex': 0
                        }
                      );
                    })),
                    SliverToBoxAdapter(child: _orderBody(title: '盲盒订单', children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          _funItem(path: 'assets/icons/icon_blindbox_delivery.png', title: '我的提货码', num: commonPageController.userData.value.statistics!.shopping![0], width: 114.w, onTap: () {
                            Get.toNamed(
                              '${AppRouters.COMMON_PAGE}${AppRouters.BLINDBOX_ORDER_PAGE}',
                              arguments: {
                                'tabIndex': 1
                              }
                            );
                          }),
                          _funItem(path: 'assets/icons/icon_blindbox_transfer.png', title: '已转提货', num: commonPageController.userData.value.statistics!.shopping![1], width: 114.w, onTap: () {
                            Get.toNamed(
                              '${AppRouters.COMMON_PAGE}${AppRouters.BLINDBOX_ORDER_PAGE}',
                              arguments: {
                                'tabIndex': 2
                              }
                            );
                          }),
                          _funItem(path: 'assets/icons/icon_blindbox_complete.png', title: '已完成', num: commonPageController.userData.value.statistics!.shopping![2], width: 114.w, onTap: () {
                            Get.toNamed(
                              '${AppRouters.COMMON_PAGE}${AppRouters.BLINDBOX_ORDER_PAGE}',
                              arguments: {
                                'tabIndex': 3
                              }
                            );
                          })
                        ],
                      )
                    ], onTap: () {
                      Get.toNamed(
                        '${AppRouters.COMMON_PAGE}${AppRouters.BLINDBOX_ORDER_PAGE}',
                        arguments: {
                          'tabIndex': 0
                        }
                      );
                    })),
                    SliverToBoxAdapter(child: _orderBody(horizontalPadding: 12.w, title: '商城订单', children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          _funItem(path: 'assets/icons/icon_payment.png', title: '待付款', num: commonPageController.userData.value.statistics!.shopping![0], width: 65.w, onTap: () {
                            Get.toNamed(
                              '${AppRouters.COMMON_PAGE}${AppRouters.STORE_ORDER_PAGE}',
                              arguments: {
                                'tabIndex': 1
                              }
                            );
                          }),
                          _funItem(path: 'assets/icons/icon_store_received.png', title: '待收货', num: commonPageController.userData.value.statistics!.shopping![1], width: 65.w, onTap: () {
                            Get.toNamed(
                              '${AppRouters.COMMON_PAGE}${AppRouters.STORE_ORDER_PAGE}',
                              arguments: {
                                'tabIndex': 2
                              }
                            );
                          }),
                          _funItem(path: 'assets/icons/icon_exchange.png', title: '退换/售后', num: commonPageController.userData.value.statistics!.shopping![2], width: 65.w, onTap: () {
                            Get.toNamed(
                              '${AppRouters.COMMON_PAGE}${AppRouters.STORE_ORDER_PAGE}',
                              arguments: {
                                'tabIndex': 0
                              }
                            );
                          }),
                          _funItem(path: 'assets/icons/icon_gift_l.png', title: '赠品', num: commonPageController.userData.value.statistics!.shopping![2], width: 65.w, onTap: () {
                            Get.toNamed(
                              '${AppRouters.COMMON_PAGE}${AppRouters.GIFT_ORDER_PAGE}'
                            );
                          })
                        ],
                      )
                    ], onTap: () {
                      Get.toNamed(
                        '${AppRouters.COMMON_PAGE}${AppRouters.STORE_ORDER_PAGE}',
                        arguments: {
                          'tabIndex': 0
                        }
                      );
                    })),
                    SliverToBoxAdapter(child: Container(
                      margin: EdgeInsets.only(top: 12.h),
                      padding: EdgeInsets.symmetric(horizontal: 16.w),
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(5.w),
                        child: Image.asset(
                          'assets/images/preferential_bg.jpg',
                          width: 343.w,
                          height: 130.h,
                          fit: BoxFit.cover,
                        ),
                      ),
                    )),
                    SliverToBoxAdapter(child: _orderBody(title: '其他信息', showAllBtn: false, topPadding: false, children: _getOtherItem().map((item) {
                      return Container(
                        padding: EdgeInsets.only(top: 12.h),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: item,
                        ),
                      );
                    }).toList())),
                    SliverToBoxAdapter(child: SizedBox(height: 38.h))
                  ]
                )))
              ],
            )
          )
        ],
      )
    );
  }

  /// 用户信息
  Widget _userHead() {
    if (!commonPageController.isAuthenticated.value) {
      return InkWellUtil.shakeProofInkWell(Container(
        height: 54.w,
        padding: EdgeInsets.only(left: 30.w),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Row(
              children: [
                Image.asset(
                  'assets/icons/icon_default_head.png',
                  width: 54.w,
                  height: 54.w,
                ),
                SizedBox(width: 12.w),
                Text(
                  '请点击登录',
                  style: TextStyle(
                    color: textWhiteColor,
                    fontSize: 18.sp,
                    fontWeight: FontWeight.bold
                  ),
                )
              ],
            ),
            Container(
              padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 6.h),
              decoration: BoxDecoration(
                color: bgWhiteColor_50,
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(20.w),
                  bottomLeft: Radius.circular(20.w)
                )
              ),
              child: Text(
                '游客身份',
                style: TextStyle(
                  color: textWhiteColor,
                  fontSize: 12.sp
                ),
              ),
            )
          ],
        ),
      ), () {
        Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.LOGIN_PAGE}');
      });
    }
    return InkWellUtil.shakeProofInkWell(Container(
      height: 54.w,
      padding: EdgeInsets.only(left: 30.w),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Row(
            children: [
              NetworkImageUtil(
                url: commonPageController.userData.value.avatar ?? '',
                nickname: commonPageController.userData.value.nickname ?? '', 
                width: 54.w, 
                height: 54.w
              ),
              SizedBox(width: 12.w),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    commonPageController.userData.value.nickname ?? '',
                    style: TextStyle(
                      color: textWhiteColor,
                      fontSize: 18.sp,
                      fontWeight: FontWeight.bold
                    ),
                  ),
                  SizedBox(height: 6.w),
                  Text(
                    '查看或编辑个人主页',
                    style: TextStyle(
                      color: textWhiteColor,
                      fontSize: 14.sp
                    ),
                  ),
                ],
              )
            ],
          ),
          Container(
            padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 6.h),
            decoration: BoxDecoration(
              color: bgWhiteColor_50,
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(20.w),
                bottomLeft: Radius.circular(20.w)
              )
            ),
            child: Text(
              commonPageController.userData.value.levelStr ?? '',
              style: TextStyle(
                color: textWhiteColor,
                fontSize: 12.sp
              ),
            ),
          )
        ],
      ),
    ), () {
      Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}');
    });
  }

  /// 资产
  Widget _assets() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 10.w),
      margin: EdgeInsets.only(top: 16.h),
      child: Container(
        height: 125.h,
        width: 355.w,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(5.w),
          image: DecorationImage(
            image: AssetImage(
              'assets/icons/icon_assets_bg.png'
            ),
            fit: BoxFit.cover
          )
        ),
        child: Column(
          children: [
            Container(
              height: 45.h,
              padding: EdgeInsets.symmetric(horizontal: 16.w),
              decoration: BoxDecoration(
                border: Border(
                  bottom: BorderSide(
                    width: 1.w,
                    color: lineColor
                  )
                )
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    '资产管理',
                    style: TextStyle(
                      color: textBlackColor,
                      fontSize: 16.sp,
                      fontWeight: FontWeight.bold
                    ),
                  ),
                  Container(
                    width: 52.w,
                    child: ButtonUtil(
                      text: '提现', 
                      fontSize: 14.sp, 
                      borderRadius: 30.w, 
                      height: 25.h,
                      onTop: () {
                        Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.WITHDRAWAL_PAGE}');
                      }
                    ),
                  )
                ],
              ),
            ),
            Expanded(child: Container(
              // padding: EdgeInsets.symmetric(horizontal: 22.w),
              alignment: Alignment.center,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  // _assetsItem('购物金', '${commonPageController.userData.value.assets!.shopping}'),
                  _assetsItem('补贴金', '${commonPageController.userData.value.assets!.subsidy}'),
                  _assetsItem('感恩值', '${commonPageController.userData.value.assets!.gratitude}'),
                  InkWellUtil.shakeProofInkWell(_assetsItem('回馈感恩值', '${commonPageController.userData.value.assets!.feedbackGratitude}'), () {
                    Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.GRATITUDE_RECORD_PAGE}');
                  })
                ],
              ),
            ))
          ],
        ),
      ),
    );
  }

  /// 资产Item
  Widget _assetsItem(String title, String value, { bool showBar = false }) {
    return Stack(
      children: [
        Container(
          width: 118.w,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                title,
                style: TextStyle(
                  color: textBlackColor,
                  fontSize: 12.sp
                ),
              ),
              SizedBox(height: 6.h),
              Text(
                value,
                style: TextStyle(
                  color: textBlackColor,
                  fontSize: 18.sp,
                  fontWeight: FontWeight.bold
                ),
              )
            ],
          ),
        ),
        Positioned(
          right: 30.w,
          top: 12.r,
          child: showBar ? InkWellUtil.shakeProofInkWell(Image.asset(
            'assets/icons/icon_estimate.png',
            width: 40.w,
            height: 20.h,
          ), () {
            Get.dialog(MessageDialog(
              title: '补贴金预估说明',
              message: '参与活动预估获得的补贴金，在最终完成任务时进行发放，以实际结算为准。',
              textAlign: TextAlign.left,
            ));
          }) : Container()
        )
      ],
    );
  }

  /// 订单Body
  Widget _orderBody({required String title, required List<Widget> children, bool showAllBtn = true,bool topPadding = true, Function? onTap, double horizontalPadding = 0}) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      margin: EdgeInsets.only(top: 12.h),
      child: Container(
        decoration: BoxDecoration(
          color: bgWhiteColor,
          borderRadius: BorderRadius.circular(5.w)
        ),
        child: Column(
          children: [
            Container(
              padding: EdgeInsets.symmetric(horizontal: 8.w),
              child: Container(
                height: 54.h,
                decoration: BoxDecoration(
                  border: Border(
                    bottom: BorderSide(
                      color: lineColor,
                      width: 1.w
                    )
                  )
                ),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      title,
                      style: TextStyle(
                        color: textBlackColor,
                        fontSize: 16.sp
                      ),
                    ),
                    showAllBtn ? InkWellUtil.shakeProofInkWell(Row(
                      children: [
                        Text(
                          '全部订单',
                          style: TextStyle(
                            color: textSubtitleColor,
                            fontSize: 14.sp
                          ),
                        ),
                        SizedBox(width: 8.w),
                        Image.asset(
                          'assets/icons/icon_arrow_right_w.png',
                          width: 8.w,
                          height: 15.h,
                        )
                      ],
                    ), () {
                      onTap!();
                    }) : Container()
                  ],
                ),
              ),
            ),
            Container(
              width: 343.w,
              padding: EdgeInsets.only(top: topPadding ? 12.h : 0, bottom: 20.h, left: horizontalPadding, right: horizontalPadding),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: children,
              ),
            ),
            SizedBox(height: 4.h)
          ],
        ),
      ),
    );
  }

  /// 功能项
  Widget _funItem({required String title, required path, required double width, required Function onTap, int num = 0}) {
    return InkWellUtil.shakeProofInkWell(Stack(
      children: [
        Container(
          width: width,
          padding: EdgeInsets.only(top: 6.h),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Image.asset(
                path,
                width: 24.w,
                height: 24.w,
              ),
              SizedBox(height: 8.h),
              Text(
                title,
                style: TextStyle(
                  color: textBlackColor,
                  fontSize: 14.sp
                ),
              )
            ],
          ),
        ),
        Positioned(
          top: 0,
          right: num <= 99 ? num < 10 ? 12.w : 6.w : 0,
          child: _angleMark(num)
        )
      ],
    ), () => onTap());
  }

  /// 获取其他Item
  List<List<Widget>> _getOtherItem() {
    List<Widget> children = [
      GetBuilder<CooperationPageController>(
        init: CooperationPageController(),
        builder: (cooperationPageController) {
          return  _funItem(path: 'assets/icons/icon_invitation_r.png', title: '邀请加入', width: 80.w, onTap: () {
            commonPageController.tabIndex.value = 1;
            Get.dialog(StatefulBuilder(
              builder: (context, setButtomSheetState) {
                return InputDialogUtil(
                  title: '邀请码加入',
                  hintText: '请输入邀请码',
                  defaultValue: '',
                  onChenge: (value) {
                    cooperationPageController.invitationCode.value = value;
                  },
                  onSubmit: () {
                    cooperationPageController.invitations();
                  }
                );
              }
            ));
          });
        },
      ),
      // _funItem(path: 'assets/icons/icon_upgrades.png', title: '会员升级', width: 80.w, onTap: () {
      //   Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.UPGRADES_PAGE}');
      // }),
      _funItem(path: 'assets/icons/icon_update_password.png', title: '修改密码', width: 80.w, onTap: () {
        Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.UPDATE_PASSWORD_PAGE}');
      }),
      _funItem(path: 'assets/icons/icon_privacy.png', title: '隐私政策', width: 80.w, onTap: () {
        Get.toNamed(
          '${AppRouters.COMMON_PAGE}${AppRouters.ARTICLE_DETAIL_PAGE}',
          arguments: {
            'articleId': 2,
            'title': '隐私政策'
          }
        );
      }),
      _funItem(path: 'assets/icons/icon_gift_y.png', title: '赠品', width: 80.w, onTap: () {
        Get.toNamed(
          '${AppRouters.COMMON_PAGE}${AppRouters.GIFT_PAGE}',
        );
      }),
      _funItem(path: 'assets/icons/icon_check_update.png', title: '版本更新', width: 80.w, onTap: () {
        commonPageController.checkAppVersion();
      }),
      _funItem(path: 'assets/icons/icon_wechat.png', title: '我的微信号', width: 80.w, onTap: () {
        Get.dialog(StatefulBuilder(
          builder: (context, setButtomSheetState) {
            return InputDialogUtil(
              title: '修改微信号',
              hintText: '请输入微信号',
              maxLength: 32,
              defaultValue: '${commonPageController.userData.value.wechat}',
              onChenge: (value) {
                commonPageController.wechat = value;
              },
              onSubmit: () {
                commonPageController.editUserWechat();
              }
            );
          }
        ));
      }),
    ];
    if (commonPageController.userData.value.teamId! >= 1) {
      children.insert(0,  _funItem(path: 'assets/icons/icon_statistics.png', title: '空间统计', width: 80.w, onTap: () {
        Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.SPACE_STATISTICS_PAGE}');
      }));
    }
    if (commonPageController.userData.value.isTeamLeader! >= 1) {
      children.insert(1,  _funItem(path: 'assets/icons/icon_one_key_recycling.png', title: '一键回收', width: 80.w, onTap: () {
        if (!commonPageController.isAuthenticated.value) {
          Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.LOGIN_PAGE}');
          return;
        }
        Get.dialog(DelDialog(
          title: '是否回收',
          message: '确定后将一键回收抢购空间中的商品', 
          onTap: () {
            commonPageController.seckillRecovery();
          }
        ));
      }));
    }
    if (commonPageController.userData.value.isWriteoffOfficer == 1) {
      children.add(
        _funItem(path: 'assets/icons/icon_qrcode_scan.png', title: '扫码核销', width: 80.w, onTap: () {
          commonPageController.startScan();
        })
      );
    }

    if (children.length < 8) {
      for (int i = 0; i <= (8 - children.length); i++) {
        children.add(Container(width: 80.w));
      }
    } else if (children.length > 8) {
      for (int i = 0; i <= (12 - children.length); i++) {
        children.add(Container(width: 80.w));
      }
    }

    List<List<Widget>> pageArr = [];
    List<Widget> itemArr = [];
    children.forEach((item) {
      if(itemArr.length == 4) {
        itemArr=[];
      }
      if(itemArr.length == 0) {
        pageArr.add(itemArr);
      }
      itemArr.add(item);
    });
    return pageArr;
  }

  /// 角标
  Widget _angleMark(int number) {
    if (number <= 0) {
      return Container();
    }
    if (number < 10) {
      return Container(
        width: 16.w,
        height: 16.w,
        alignment: Alignment.center,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(16.w),
          color: bgMainColor,
          border: Border.all(
            width: 1.w,
            color: bgWhiteColor
          )
        ),
        child: Text(
          '$number',
          style: TextStyle(
            color: textWhiteColor,
            fontSize: 12.sp
          ),
        ),
      );
    }
    if (number <= 99) {
      return Container(
        padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 1.h),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(16.w),
          color: bgMainColor,
          border: Border.all(
            width: 1.w,
            color: bgWhiteColor
          )
        ),
        child: Text(
          '$number',
          style: TextStyle(
            color: textWhiteColor,
            fontSize: 12.sp
          ),
        ),
      );
    }
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 1.h),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(16.w),
        color: bgMainColor,
        border: Border.all(
          width: 1.w,
          color: bgWhiteColor
        )
      ),
      child: Text(
        '99+',
        style: TextStyle(
          color: textWhiteColor,
          fontSize: 12.sp
        ),
      ),
    );
  }

}